define(function (require, exports, module) {
    require("apps/ebom/page.css");
    require("apps/grid");

    exports.init = function (ctx, uuid) {
        var page = new $.PageDomFactory(uuid);
        exports.pageFactory = page;

        exports.getChooseData = function(){
            var sel = pageListComponent.grid.datagrid("getChecked");
            return sel;
        };

        var pageListComponent = new $.PageListComponent(uuid, {
            view: {
                grid: "grid",
                myToolbar: "news_tb",
                colbar: "user_list_btn"
            },
            configs: {
                gridUrl: ctx + "/app/api/ebom/list?status=PUBLISH",
                idField: "id",
                treeField: "eName",
                gridColumns: [
                    {
                        field: 'id',
                        checkbox:true
                    },
                    {
                        field: 'temp1',
                        hidden: true
                    },
                    {
                        field: 'eName',
                        title: '名称',
                        width: 150,
                        align: 'left'
                    },
                    {
                        field: 'code',
                        title: '编码',
                        width: 100,
                        align: 'left'
                    },
                    {
                        field: 'pBomDes',
                        title: '设计结构',
                        width: 100,
                        align: 'left'
                    },
                    {
                        field: 'bomType',
                        title: '是否装配',
                        width: 100,
                        hidden:true,
                        align: 'left',
                        formatter: function (value, row, index) {
                            return value == "E_BOM_TYPE_UN_BUILD" ? "未装配" : "已装配";
                        }
                    },
                    {
                        field: 'description',
                        title: '功能',
                        width: 100,
                        align: 'left',
                        hidden:true
                    },
                    {
                        field: 'remark',
                        title: '备注',
                        hidden: true,
                        width: 50,
                        align: 'left'
                    },
                    {
                        field: 'cover',
                        title: '封面',
                        width: 100,
                        hidden:true,
                        align: 'left',
                        formatter: function (value, row, index) {
                            return "<img src=\"" + ctx + "/print/" + value + "\" style=\"width:48px;height:32px;\"/>"
                        }
                    },
                    {
                        field: 'createTime',
                        title: '装配时间',
                        width: 100,
                        hidden:true,
                        align: 'left'
                    }
                ],
                singleSelect:true,
                onLoadSuccess: $.noop
            },
            events: {
                renderColBarBefore: function (key, row) {
                    return true;
                },
                onClickColBtn: function (context, btn, row) {
                    switch (btn.key) {
                        case "view":
                            whenView(context, row);
                            break;
                        default :
                            break;
                    }
                },
                onClickToolbarBtn: function (context, btn) {
                    switch (btn.key) {
                        case "search_all":
                            context.searchAll();
                            break;
                        case "search":
                            context.search(btn.href, "装配结构搜索", "ebom_search");
                            break;
                        default :
                            break;
                    }
                }
            }
        });
        var globalWindow = new $.PageWindow();

        function whenView(context, row) {
            globalWindow.create({
                href: ctx + "/app/api/ebom/view?id=" + row.id,
                width:800,
                title: row.eName + "的结构查看"
            });
            globalWindow.open();
        }
    }
});